package main

import (
	"encoding/json"
	"log"
	"sync"
	pbCity "wire/api/city"
	pbUser "wire/api/user"
	clientGrpc "wire/client/grpc"
	clientHttp "wire/client/http"

	"gitee.com/go-mod/framework/config"
)

// cd cmd/client go run main.go
func main() {
	config.Init()

	var wg sync.WaitGroup
	wg.Add(2)

	go func() {
		defer wg.Done()
		grpcClient := clientGrpc.NewClient()
		defer grpcClient.Close()

		info, err := grpcClient.UserGet(&pbUser.GetRequest{Id: 10086})
		if err != nil {
			log.Printf("grpcClient UserGet err: %+v\n", err)
		}
		log.Printf("grpcClient UserGet: %+v\n", info)

		cityAll, err := grpcClient.CityAll(&pbCity.AllRequest{Status: 1})
		if err != nil {
			log.Printf("grpcClient CityAll err: %+v\n", err)
		}
		log.Printf("grpcClient CityAll: %+v\n", cityAll)
	}()

	go func() {
		defer wg.Done()
		httpClient := clientHttp.NewClient()

		hinfo, err := httpClient.UserGet(&pbUser.GetRequest{Id: 10087})
		if err != nil {
			log.Printf("httpClient UserGet err: %+v\n", err)
		}
		hinfoJson, _ := json.Marshal(hinfo)
		log.Printf("httpClient UserGet: %+v\n", string(hinfoJson))

		hcityAll, err := httpClient.CityAll(&pbCity.AllRequest{Status: 1})
		if err != nil {
			log.Printf("httpClient CityAll err: %+v\n", err)
		}
		hcityAllJson, _ := json.Marshal(hcityAll)
		log.Printf("httpClient CityAll: %+v\n", string(hcityAllJson))
	}()

	wg.Wait()
}
